package com.atguigu.yygh.user.service.impl;

import com.atguigu.yygh.cmn.client.DictFeignClient;
import com.atguigu.yygh.enums.DictEnum;
import com.atguigu.yygh.model.user.Patient;
import com.atguigu.yygh.user.mapper.PatientMapper;
import com.atguigu.yygh.user.service.PatientService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class PatientServiceImpl extends
        ServiceImpl<PatientMapper, Patient> implements PatientService {

    @Autowired
    private DictFeignClient dictFeignClient;


    @Override
    public List<Patient> findAllUserId(Long userId) {
        List<Patient> list = baseMapper.selectList(new QueryWrapper<Patient>().eq("user_id", userId));

        list.stream().forEach(item -> {
            //其他参数封装
            this.packPatient(item);
        });
        
        return list;
    }

    @Override
    public Patient getPatientId(Long id) {
        return this.packPatient(baseMapper.selectById(id));
    }

    private Patient packPatient(Patient item) {
        //根据证件类型编码，获取证件类型具体指
        String certificatesTypeString =
                dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), item.getCertificatesType());
        //省市区
        String proName = dictFeignClient.getName(item.getProvinceCode());
        String cityName = dictFeignClient.getName(item.getCityCode());
        String distName = dictFeignClient.getName(item.getDistrictCode());
        item.getParam().put("certificatesTypeString", certificatesTypeString);
        // patient.getParam().put("contactsCertificatesTypeString", contactsCertificatesTypeString);
        item.getParam().put("provinceString", proName);
        item.getParam().put("cityString", cityName);
        item.getParam().put("districtString", distName);
        item.getParam().put("fullAddress", proName + cityName + distName + item.getAddress());
        return item;


    }
}
